package com.aspose.cells;

import java.util.ArrayList;

public class PivotField {
   PivotFieldCollection a;
   zbrr b;
   zbrs c;
   PivotItemCollection d;
   zbro e;
   int f;
   boolean g = false;
   zbqs h;
   zbqn i;
   zbrl j;
   PivotField k;
   PivotTable l;
   int m;
   boolean n;
   boolean o;
   boolean p;
   boolean q;
   boolean r;
   String s = "{2946ED86-A175-432a-8AC1-64E0C546D7DE}";
   int t;
   boolean u;
   private boolean v;

   public PivotItemCollection getPivotItems() {
      return this.d;
   }

   public SxRng getRange() {
      return this.h != null ? this.h.j : null;
   }

   void a() {
      if (this.h != null && this.h.j != null) {
         this.h.j = null;
      }

   }

   void b() {
      PivotItem var1 = new PivotItem(this.d);
      this.d.a(var1);
      var1.setIndex(0);
   }

   public PivotFilter getPivotFilterByType(int type) {
      new ArrayList();

      for(int var3 = 0; var3 < this.l.getPivotFilters().getCount(); ++var3) {
         PivotFilter var4 = this.l.getPivotFilters().get(var3);
         if (var4.b == type && this.t == var4.a) {
            return var4;
         }
      }

      return null;
   }

   public ArrayList getPivotFilters() {
      ArrayList var1 = new ArrayList();

      for(int var2 = 0; var2 < this.l.getPivotFilters().getCount(); ++var2) {
         PivotFilter var3 = this.l.getPivotFilters().get(var2);
         if (this.t == var3.a) {
            com.aspose.cells.b.a.a.ze.a(var1, (Object)var3);
         }
      }

      return var1;
   }

   PivotField(PivotTable pivotTable, PivotFieldCollection dataFields) {
      this.l = pivotTable;
      this.a = pivotTable.getBaseFields();
      this.d = new PivotItemCollection(this);
      this.m = 1;

      for(int var3 = 0; var3 < 2 && var3 < dataFields.getCount(); ++var3) {
         PivotItem var4 = new PivotItem(this.d);
         this.d.a(var4);
         var4.setIndex(var3);
         var4.e = dataFields.get(var3);
      }

      this.k = this;
   }

   PivotField(PivotFieldCollection pivotFields) {
      this.a = pivotFields;
      this.i = new zbqn();
      this.j = new zbrl(this);
      this.b = new zbrr(this);
      this.c = new zbrs(this);
      this.d = new PivotItemCollection(this);
      this.k = this;
   }

   PivotField(PivotFieldCollection pivotFields, PivotField pivotField) {
      this.a = pivotFields;
      this.k = pivotField;
      this.i = new zbqn(this);
      this.m = 8;
   }

   PivotField() {
      this.d = new PivotItemCollection(this);
   }

   void a(PivotField var1) {
      if (this.b != null) {
         this.b.a(var1.b);
      }

      if (this.c != null) {
         this.c.a(var1.c);
      }

      if (this.i != null) {
         this.i.a(var1.i);
      }

      if (this.j != null) {
         this.j.a(var1.j);
      }

      if (var1.e != null) {
         this.e = new zbro();
         this.e.a(var1.e);
      }

      this.setShowCompact(var1.getShowCompact());
      this.o = var1.o;
      this.u = var1.u;
      this.setRepeatItemLabels(var1.isRepeatItemLabels());
      if (this.d != null && var1.d != null) {
         this.d.b = new ArrayList(var1.d.getCount());

         for(int var2 = 0; var2 < var1.d.getCount(); ++var2) {
            this.d.a(var1.d.get(var2));
         }
      }

   }

   int c() {
      return this.t;
   }

   void a(int var1) {
      this.t = var1;
   }

   public void initPivotItems() {
      if (this.d.getCount() == 0 && this.h != null && this.h.c != null) {
         int var1 = this.h.c.size();

         for(int var2 = 0; var2 < var1; ++var2) {
            PivotItem var3 = new PivotItem(this.d);
            this.d.a(var3);
            var3.setIndex(var2);
         }
      }

   }

   void d() {
      if (this.d.getCount() == 0 && this.h != null && this.h.j.d != null) {
         int var1 = this.h.j.d.size();

         for(int var2 = 0; var2 < var1; ++var2) {
            PivotItem var3 = new PivotItem(this.d);
            this.d.a(var3);
            var3.setIndex(var2);
         }
      }

   }

   void e() {
      this.d = new PivotItemCollection(this);
   }

   void f() {
      if (this.d.getCount() > 0) {
         for(int var1 = 0; var1 < this.d.getCount(); ++var1) {
            PivotItem var2 = this.d.get(var1);
            var2.i = var2.getValue();
         }
      }

   }

   boolean g() {
      return this.k.h.e();
   }

   boolean h() {
      return this.k.u;
   }

   void a(boolean var1) {
      this.k.u = var1;
   }

   public boolean isCalculatedField() {
      return this.k != null && this.k.h != null ? this.k.h.m() : false;
   }

   public String getCalculatedFieldFormula() {
      return this.k != null && this.k.h != null ? zase.H(this.k.h.d) : null;
   }

   boolean i() {
      return this.t == -2 || this.t == 65534;
   }

   public int getBaseIndex() {
      return this.k.c();
   }

   public void setBaseIndex(int value) {
      this.k.a(value);
   }

   void b(int var1) {
      this.k.a(var1);
   }

   public int getPosition() {
      PivotFieldCollection var1 = this.a.b.fields(this.m);
      return var1.d(this);
   }

   public String getName() {
      if (this.i()) {
         return this.l.b.h;
      } else {
         return this.k.h != null ? this.k.h.a : null;
      }
   }

   boolean j() {
      return this.a != null && this.a.c == 8;
   }

   public String getDisplayName() {
      if (this.i()) {
         return this.l.b.h;
      } else {
         return this.j() ? this.i.b() : this.b.b;
      }
   }

   public void setDisplayName(String value) {
      if (this.i()) {
         this.l.b.h = value;
      } else {
         if (this.j()) {
            this.i.b(value);
         } else {
            this.b.b = value;
         }

      }
   }

   public void setSubtotals(int subtotalType, boolean shown) {
      this.n();
      if (this.h() && this.m == 8) {
         throw new CellsException(12, "Subtotals are only valid for nondata fields");
      } else {
         this.a.b.s = false;
         switch(subtotalType) {
         case 0:
            if (shown) {
               this.b.a = subtotalType;
            } else if (this.getSubtotals(0)) {
               this.b.a = 1;
            }
            break;
         case 1:
            if (this.isAutoSubtotals() != shown) {
               if (shown) {
                  this.b.a = subtotalType;
               } else {
                  this.b.a = 0;
               }
            }
            break;
         default:
            if (this.getSubtotals(subtotalType) != shown) {
               if (this.isAutoSubtotals()) {
                  this.b.a &= 254;
               }

               this.b.a &= ~(subtotalType & '\uffff');
               this.b.a |= shown ? subtotalType & '\uffff' : 0;
            }
         }

      }
   }

   public boolean getSubtotals(int subtotalType) {
      if (!this.i() && (!this.h() || this.m != 8)) {
         switch(subtotalType) {
         case 0:
            return this.b.a == 0;
         case 1:
            return this.b.a == 1;
         default:
            return (this.b.a & '\uffff' & subtotalType & '\uffff') != 0;
         }
      } else {
         return false;
      }
   }

   boolean k() {
      if (!this.i() && (!this.h() || this.m() == 1 || this.m != 8)) {
         return this.b.a == 0;
      } else {
         return true;
      }
   }

   public boolean isAutoSubtotals() {
      if (this.i()) {
         return true;
      } else if (this.k()) {
         return false;
      } else {
         return this.b.a == 1;
      }
   }

   public void setAutoSubtotals(boolean value) {
      this.n();
      if (this.j()) {
         throw new CellsException(12, "Subtotals are only valid for nondata fields");
      } else {
         if (value) {
            this.b.a = 1;
         } else if (this.b.a == 1) {
            this.b.a = 0;
         }

         this.a.b.s = false;
      }
   }

   /** @deprecated */
   public boolean dragToColumn() {
      return this.getDragToColumn();
   }

   public boolean getDragToColumn() {
      return this.i() ? true : this.k.c.a(4);
   }

   public void setDragToColumn(boolean value) {
      if (!this.i()) {
         this.k.c.a(value, 4);
      }
   }

   /** @deprecated */
   public boolean dragToHide() {
      return this.getDragToHide();
   }

   public boolean getDragToHide() {
      return this.i() ? true : this.k.c.a(16);
   }

   public void setDragToHide(boolean value) {
      if (!this.i()) {
         this.k.c.a(value, 16);
      }
   }

   /** @deprecated */
   public boolean dragToRow() {
      return this.getDragToRow();
   }

   public boolean getDragToRow() {
      return this.i() ? true : this.k.c.a(2);
   }

   public void setDragToRow(boolean value) {
      if (!this.i()) {
         this.k.c.a(value, 2);
      }
   }

   /** @deprecated */
   public boolean dragToPage() {
      return this.getDragToPage();
   }

   public boolean getDragToPage() {
      return this.i() ? false : this.k.c.a(8);
   }

   public void setDragToPage(boolean value) {
      if (!this.i()) {
         this.k.c.a(value, 8);
      }
   }

   public boolean getDragToData() {
      if (this.i()) {
         return true;
      } else {
         return !this.k.c.a(32);
      }
   }

   public void setDragToData(boolean value) {
      this.k.c.a(!value, 32);
   }

   public boolean isMultipleItemSelectionAllowed() {
      return this.n;
   }

   public void setMultipleItemSelectionAllowed(boolean value) {
      this.n = value;
   }

   public boolean isRepeatItemLabels() {
      return this.q;
   }

   public void setRepeatItemLabels(boolean value) {
      this.q = value;
   }

   public boolean isIncludeNewItemsInFilter() {
      return this.r;
   }

   public void setIncludeNewItemsInFilter(boolean value) {
      this.r = value;
   }

   public boolean isInsertPageBreaksBetweenItems() {
      return this.k.c.a(16384);
   }

   public void setInsertPageBreaksBetweenItems(boolean value) {
      this.k.c.a(value, 16384);
   }

   /** @deprecated */
   public boolean showAllItems() {
      return this.getShowAllItems();
   }

   public boolean getShowAllItems() {
      return this.i() ? true : this.k.c.a(1);
   }

   public void setShowAllItems(boolean value) {
      if (!this.i()) {
         this.k.c.a(value, 1);
      }
   }

   public boolean isAutoSort() {
      if (this.i()) {
         return true;
      } else {
         switch(this.m) {
         case 1:
         case 2:
         case 4:
            return this.c.a(512);
         case 3:
         default:
            return false;
         }
      }
   }

   public void setAutoSort(boolean value) {
      if (!this.i()) {
         switch(this.m) {
         case 1:
         case 2:
         case 4:
            this.c.a(value, 512);
         case 3:
         default:
            this.a.b.s = false;
         }
      }
   }

   public boolean isAscendSort() {
      if (this.i()) {
         return true;
      } else {
         return !this.isAutoSort() ? true : this.c.a(1024);
      }
   }

   public void setAscendSort(boolean value) {
      this.n();
      this.c.a(value, 1024);
      this.setAutoSort(true);
      this.a.b.s = false;
   }

   public int getAutoSortField() {
      if (this.i()) {
         return -1;
      } else {
         switch(this.m) {
         case 1:
         case 2:
         case 4:
            return this.c.c();
         case 3:
         default:
            return -1;
         }
      }
   }

   public void setAutoSortField(int value) {
      this.n();
      switch(this.m) {
      case 1:
      case 2:
      case 4:
         if (!this.isAutoSort()) {
            return;
         } else if (value == -1 || this.c.h == (short)value) {
            return;
         } else {
            zbqw var2;
            if (this.e == null) {
               this.e = new zbro();
               var2 = new zbqw();
               var2.b((int)65534);
               var2.a((byte)8);
               com.aspose.cells.b.a.a.ze.a(var2.c, (Object)value);
               com.aspose.cells.b.a.a.ze.a(this.e.e, (Object)var2);
            } else if (this.e.e.size() == 0) {
               var2 = new zbqw();
               var2.b((int)65534);
               var2.a((byte)8);
               com.aspose.cells.b.a.a.ze.a(var2.c, (Object)value);
               com.aspose.cells.b.a.a.ze.a(this.e.e, (Object)var2);
            } else {
               ArrayList var3 = ((zbqw)((zbqw)this.e.e.get(0))).c;
               if (var3.size() == 0) {
                  com.aspose.cells.b.a.a.ze.a(var3, (Object)value);
               } else {
                  var3.set(0, value);
               }
            }

            this.c.h = (short)value;
            this.a.b.s = false;
         }
      case 3:
      default:
      }
   }

   public boolean isAutoShow() {
      return !this.i() && !this.h() ? this.c.a(2048) : false;
   }

   public void setAutoShow(boolean value) {
      this.n();
      if (!this.h()) {
         this.c.a(value, 2048);
      }

      this.a.b.s = false;
   }

   public boolean isAscendShow() {
      return this.isAutoShow() ? this.c.a(4096) : true;
   }

   public void setAscendShow(boolean value) {
      this.n();
      if (this.isAutoShow()) {
         this.c.a(value, 4096);
      }

      this.a.b.s = false;
   }

   public int getAutoShowCount() {
      if (!this.i() && !this.h()) {
         return this.f > 0 ? this.f : this.c.c;
      } else {
         return 10;
      }
   }

   public void setAutoShowCount(int value) {
      this.n();
      if (this.isAutoShow()) {
         this.c.c = (byte)value;
         this.a.b.s = false;
      }

   }

   public int getAutoShowField() {
      return !this.i() && !this.h() ? this.c.b() : -1;
   }

   public void setAutoShowField(int value) {
      this.n();
      if (!this.h() && this.isAutoShow()) {
         this.c.i = (short)value;
      }
   }

   public int getFunction() {
      if (this.i()) {
         return 0;
      } else {
         return this.h() ? this.i.a : 0;
      }
   }

   public void setFunction(int value) {
      this.n();
      if (this.h()) {
         this.i.a = value;
      }

      this.a.b.s = false;
   }

   public int getDataDisplayFormat() {
      if (this.i()) {
         return 0;
      } else {
         return this.h() ? this.i.b : 0;
      }
   }

   public void setDataDisplayFormat(int value) {
      this.n();
      if (this.h()) {
         this.a.b.s = false;
         this.i.b = value;
         switch(value) {
         case 0:
            this.i.c = 0;
            this.i.d = 0;
         case 1:
         case 2:
         default:
            break;
         case 3:
         case 5:
         case 6:
         case 7:
            this.i.e = 10;
            break;
         case 4:
         case 8:
            this.i.e = 10;
            this.i.d = 0;
         }
      }

   }

   /** @deprecated */
   public int getBaseField() {
      if (this.i()) {
         return 0;
      } else {
         return this.h() ? this.i.c : 0;
      }
   }

   /** @deprecated */
   public void setBaseField(int value) {
      this.n();
      if (this.h()) {
         switch(this.i.b) {
         case 1:
         case 2:
         case 3:
         case 4:
            PivotField var2 = this.a.b.getBaseFields().get(value);
            this.i.c = value;
         default:
            this.a.b.s = false;
         }
      }

   }

   public int getBaseFieldIndex() {
      if (this.i()) {
         return 0;
      } else {
         return this.h() ? this.i.c : 0;
      }
   }

   public void setBaseFieldIndex(int value) {
      this.n();
      if (this.h()) {
         switch(this.i.b) {
         case 1:
         case 2:
         case 3:
         case 4:
            PivotField var2 = this.a.b.getBaseFields().get(value);
            this.i.c = value;
         default:
            this.a.b.s = false;
         }
      }

   }

   public int getBaseItemPosition() {
      if (this.i()) {
         return 2;
      } else if (this.h()) {
         switch(this.i.d) {
         case 32763:
         case 1048828:
            return 0;
         case 32764:
         case 1048829:
            return 1;
         default:
            return 2;
         }
      } else {
         return 2;
      }
   }

   public void setBaseItemPosition(int value) {
      this.n();
      if (this.h()) {
         switch(value) {
         case 0:
            if (this.a.b.a.b.getWorkbook().k()) {
               this.i.d = 1048828;
            } else {
               this.i.d = 32763;
            }
            break;
         case 1:
            if (this.a.b.a.b.getWorkbook().k()) {
               this.i.d = 1048829;
            } else {
               this.i.d = 32764;
            }
            break;
         case 2:
         default:
            this.i.d = 0;
         }

         this.a.b.s = false;
      }

   }

   /** @deprecated */
   public int getBaseItem() {
      if (this.i()) {
         return 0;
      } else {
         return this.h() ? this.i.d : 0;
      }
   }

   /** @deprecated */
   public void setBaseItem(int value) {
      this.n();
      if (this.h()) {
         switch(this.i.b) {
         case 1:
         case 2:
         case 3:
            PivotItem var2 = this.a.b.getBaseFields().get(this.i.c).d.get(value);
            this.i.d = value;
         default:
            this.a.b.s = false;
         }
      }

   }

   public int getBaseItemIndex() {
      if (this.i()) {
         return 0;
      } else {
         return this.h() ? this.i.d : 0;
      }
   }

   public void setBaseItemIndex(int value) {
      this.n();
      if (this.h()) {
         switch(this.i.b) {
         case 1:
         case 2:
         case 3:
            PivotItem var2 = this.a.b.getBaseFields().get(this.i.c).d.get(value);
            this.i.d = value;
         default:
            this.a.b.s = false;
         }
      }

   }

   public short getCurrentPageItem() {
      return this.k.j != null ? this.k.j.b : 32765;
   }

   public void setCurrentPageItem(short value) {
      if (this.k.j != null) {
         this.k.j.b = value;
         this.a.b.s = false;
      }

   }

   public int getNumber() {
      if (this.i()) {
         return 0;
      } else {
         return this.j() ? this.i.e : this.c.d;
      }
   }

   public void setNumber(int value) {
      this.n();
      if (this.j()) {
         this.i.a((String)null);
         this.i.e = (short)value;
      } else {
         this.c.a((String)null);
         this.c.d = (short)value;
      }

      this.a.b.s = false;
   }

   public boolean getInsertBlankRow() {
      if (this.i()) {
         return true;
      } else {
         return (this.c.b & 255 & 64) != 0;
      }
   }

   public void setInsertBlankRow(boolean value) {
      if (!this.i()) {
         if (value) {
            this.c.b = (byte)(this.c.b | 64);
         } else {
            this.c.b = (byte)(this.c.b & 191);
         }

      }
   }

   public boolean getShowSubtotalAtTop() {
      if (this.i()) {
         return true;
      } else {
         return (this.c.b & 255 & 128) != 0;
      }
   }

   public void setShowSubtotalAtTop(boolean value) {
      if (!this.i()) {
         if (value) {
            this.c.b = (byte)(this.c.b | 128);
         } else {
            this.c.b = (byte)(this.c.b & 127);
         }

      }
   }

   public boolean getShowInOutlineForm() {
      if (this.i()) {
         return true;
      } else {
         return (this.c.b & 255 & 32) != 0;
      }
   }

   public void setShowInOutlineForm(boolean value) {
      if (!this.i()) {
         if (value) {
            this.c.b = (byte)(this.c.b | 32);
         } else {
            this.c.b = (byte)(this.c.b & 223);
         }

      }
   }

   void c(int var1) {
      if (this.j()) {
         this.i.e = (short)var1;
      } else {
         this.c.d = (short)var1;
      }

   }

   public String getNumberFormat() {
      String var1 = "";
      if (this.i()) {
         var1 = "";
      } else if (this.j()) {
         var1 = this.i.a();
      } else {
         var1 = this.c.a();
      }

      if (var1 == null) {
         var1 = "";
      }

      return var1;
   }

   public void setNumberFormat(String value) {
      this.n();
      if (this.j()) {
         this.i.e = 0;
         this.i.a(value);
      } else {
         this.c.d = 0;
         this.c.a(value);
      }

      this.a.b.s = false;
   }

   public boolean isHiddenItem(int index) {
      if (this.h()) {
         return false;
      } else {
         return this.d.getCount() == 0 ? false : this.d.get(index).isHidden();
      }
   }

   public void hideItem(int index, boolean isHidden) {
      if (this.j()) {
         throw new CellsException(12, "You can't hide/unhide one of the ");
      } else {
         this.d.get(index).setHidden(isHidden);
      }
   }

   public boolean isHiddenItemDetail(int index) {
      if (this.h()) {
         return false;
      } else {
         return this.d.getCount() == 0 ? false : this.d.get(index).a();
      }
   }

   public void hideItemDetail(int index, boolean isHiddenDetail) {
      if (this.j()) {
         throw new CellsException(12, "You can't hide/unhide detail one of the item");
      } else {
         this.d.get(index).a(isHiddenDetail);
      }
   }

   public void hideDetail(boolean isHiddenDetail) {
      if (this.j()) {
         throw new CellsException(12, "You can't hide/unhide data field's detail");
      } else {
         for(int var2 = 0; var2 < this.d.getCount(); ++var2) {
            this.d.get(var2).a(isHiddenDetail);
         }

      }
   }

   public void hideItem(String itemValue, boolean isHidden) {
      if (this.j()) {
         throw new CellsException(12, "You can't hide/unhide one of the ");
      } else {
         PivotItem var3 = this.d.get(itemValue);
         if (var3 != null) {
            var3.setHidden(isHidden);
         }

      }
   }

   public String[] getItems() {
      int var1 = this.d.getCount();
      String[] var2 = new String[var1];

      for(int var3 = 0; var3 < var1; ++var3) {
         var2[var3] = this.d.get(var3).getName();
         if (var2[var3] == null) {
            var2[var3] = "(blank)";
         }
      }

      return var2;
   }

   public String[] getOriginalItems() {
      if (this.h != null && this.h.c != null) {
         if (this.h.c.size() == 0) {
            if (this.h.t()) {
               return null;
            }

            if (this.h.a().n != null) {
               this.h.a().n.a(this.h);
            }

            if (this.h.t()) {
               return null;
            }
         }

         int var1 = this.h.c.size();
         String[] var2 = new String[var1];

         for(int var3 = 0; var3 < var1; ++var3) {
            Object var4 = ((zbmb)this.h.c.get(var3)).a;
            if (var4 == null) {
               var2[var3] = "(blank)";
            } else {
               var2[var3] = com.aspose.cells.b.a.zr.a(var4);
            }
         }

         return var2;
      } else {
         return null;
      }
   }

   public int getItemCount() {
      return this.d.getCount();
   }

   public void addCalculatedItem(String name, String formula) {
      switch(this.m) {
      case 4:
      case 8:
         return;
      default:
         zaus var3 = null;
         PivotField var4 = this.k;
         if (this.k == null) {
            var4 = this;
         } else {
            var4 = this.k;
         }

         zauk var5 = var4.a.b.d;
         if (var4.h.c == null) {
            var4.h.c = new ArrayList();
         }

         var3 = new zaus(var5, this, name, formula, this.m, var4.h.c.size());
         zbmb var6 = new zbmb();
         var6.b = true;
         var6.a = name;
         com.aspose.cells.b.a.a.ze.a(var4.h.c, (Object)var6);
         var5.b(this.c());
         if (var5.v == null) {
            var5.v = new zaur();
         }

         var5.v.a(var3);
         var3.a(this.getBaseIndex(), formula);
         if (this.k != null && this.d != null) {
            PivotItem var7 = new PivotItem(this.d);
            var7.setIndex(this.d.getCount());
            this.d.a(var7);
            var7.b(true);
         }

      }
   }

   boolean l() {
      if (this.d != null) {
         for(int var1 = 0; var1 < this.d.getCount(); ++var1) {
            PivotItem var2 = this.d.get(var1);
            if (var2.b()) {
               return true;
            }
         }
      }

      return false;
   }

   int m() {
      return this.b.a();
   }

   public boolean getShowCompact() {
      return this.v;
   }

   public void setShowCompact(boolean value) {
      this.v = value;
   }

   private void n() {
      if (this.i()) {
         throw new CellsException(12, "You can't operate the field ");
      }
   }
}
